package com.springbootdemo.demo.exception;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;


/**
 * 全局异常处理，@RestControllerAdvice代表当前类是一个异常通知类，用来捕获controller层抛出的异常
 * 在定义的方法中添加上@ExceptionHandler即可实现异常的捕捉
 */
@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {


    @ExceptionHandler(Exception.class)
    public String exceptionHandler(Exception exception, Model model){

        return "error";
    }
}
